home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d18 / nrpas13.arc / RTNEWT.PAS < prev    next >
Pascal/Delphi Source File  |  1991-05-01  |  744b  |  27 lines

  1. FUNCTION rtnewt(x1,x2,xacc: real): real;
  2. (* Programs using routine RTNEWT must externally define procedure
  3. funcd(x,f,df:real) which returns the function value f and its
  4. derivative df at the point x. *)
  5. LABEL 99;
  6. CONST
  7.    jmax=20;
  8. VAR
  9.    df,dx,f,rtn: real;
  10.    j: integer;
  11. BEGIN
  12.    rtn := 0.5*(x1+x2);
  13.    FOR j := 1 TO jmax DO BEGIN
  14.       funcd(rtn,f,df);
  15.       dx := f/df;
  16.       rtn := rtn-dx;
  17.       IF ((x1-rtn)*(rtn-x2) < 0.0) THEN BEGIN
  18.          writeln('pause in routine RTNEWT');
  19.          writeln('jumped out of brackets'); readln
  20.       END;
  21.       IF (abs(dx) < xacc) THEN GOTO 99
  22.    END;
  23.    writeln('pause in routine RTNEWT');
  24.    writeln('maximum number of iterations exceeded'); readln;
  25. 99:   rtnewt := rtn
  26. END;
  27.